package com.egdd.video.controller;


import com.egdd.video.common.api.CommonResult;
import com.egdd.video.mbg.model.Albums;
import com.egdd.video.service.iml.AlbumsServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Api(tags = "AlbumsController",description = "视频合集信息")
@RequestMapping(value = "/albums")
@Controller
public class AlbumsController {
    @Autowired
    AlbumsServiceImpl albumsService;

    private static final Logger LOGGER = LoggerFactory.getLogger(AlbumsController.class);

    @ApiOperation("根据分类id获取视频合集列表信息")
    @RequestMapping(value = "/getAlbumsByCategoryId",method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<List<Albums>> getAlbumsByCategoryId(int id){
       return CommonResult.success(albumsService.getAlbumsByCategoryId(id));
    }


    @ApiOperation("查询所有视频合集信息")
    @RequestMapping(value = "/getAllAlbums",method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<List<Albums>> getAllAlbums(){
       return CommonResult.success(albumsService.getAllAlbums());
    }


    @ApiOperation("增加一个视频合集信息")
    @ResponseBody
    @RequestMapping(value = "/addAlbums",method = RequestMethod.POST)
    public CommonResult<Albums> addAlbums(@RequestBody  Albums albums){
        int count = albumsService.addAlbums(albums);
        if (count==1){
            LOGGER.debug("视频合集添加成功");
            return CommonResult.success(albums);
        }else {
            LOGGER.debug("视频合集添加失败");
            return CommonResult.failed("视频合集添加失败");
        }
    }

    @ApiOperation("根据合集id删除对应的视频合集信息")
    @RequestMapping(value = "/delAlbumsById",method = RequestMethod.GET)
    @ResponseBody
    public CommonResult delAlbumsById(int id){
        int count = albumsService.delAlbumsById(id);
        if (count==1){
            LOGGER.debug("视频合集删除成功成功");
            return CommonResult.success("视频合集删除成功");
        }else {
            LOGGER.debug("视频合集删除失败");
            return CommonResult.failed("视频合集删除失败");
        }
    }

}
